use std::cell::RefCell;
use std::rc::Rc;
use crate::instruction::instruction::Instruction;
use crate::vm_thread::{VMFrame, VMThread};
use crate::vm_val::{VMValEnum, VMValFloat};

pub struct fconst_0 {}

impl Instruction for fconst_0 {
    fn exec(&mut self, frame: Rc<RefCell<VMFrame>>, thread: &VMThread) {
        frame.borrow().operand_stack.borrow_mut().push(VMValEnum::VMValFloat {
            val: VMValFloat {
                num: 0.0
            }
        });
    }

    fn to_string(&self) -> String {
        String::from("fconst_0")
    }
}


pub struct fconst_1 {}

impl Instruction for fconst_1 {
    fn exec(&mut self, frame: Rc<RefCell<VMFrame>>, thread: &VMThread) {
        frame.borrow().operand_stack.borrow_mut().push(VMValEnum::VMValFloat {
            val: VMValFloat {
                num: 1.0
            }
        });
    }

    fn to_string(&self) -> String {
        String::from("fconst_1")
    }
}

pub struct fconst_2 {}

impl Instruction for fconst_2 {
    fn exec(&mut self, frame: Rc<RefCell<VMFrame>>, thread: &VMThread) {
        frame.borrow().operand_stack.borrow_mut().push(VMValEnum::VMValFloat {
            val: VMValFloat {
                num: 2.0
            }
        });
    }

    fn to_string(&self) -> String {
        String::from("fconst_2")
    }
}
